package com.tencent.iov.cowin.befsale.clue.service.clue.impl;

import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.ClueExpireRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.QueryClueCustomerCollectAllRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueExpirePesponse;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueFollowHeadResponse;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueFollowHeadTypeResponse;
import com.tencent.iov.cowin.befsale.clue.domain.clue.po.ClueCustomerCollect;
import com.tencent.iov.cowin.befsale.clue.service.clue.ClueCustomerCollectByEmpService;
import com.tencent.iov.cowin.befsale.clue.service.clue.ClueCustomerCollectService;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.boot.common.util.EmptyUtils;
import com.software.boot.common.util.ValidateUtils;
import com.software.common.config.SearchLocalHeader;
import com.software.common.enums.SCRMRequestHeaderEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Describe: 线索客户宽表_Service实现层
 * @author: whp
 * @created: 2021-12-23 14:53:39
 * @version: 1.0
 */
@Slf4j
@Service
public class ClueCustomerCollectByEmpServiceImpl implements ClueCustomerCollectByEmpService {

	@Autowired
	private ClueCustomerCollectService clueCustomerCollectService;



	/**
	 * 根据条件查询对象Page记录
	 * @param request
	 * @return 查询结果
	 */
	@Override
	public PageResponse<ClueCustomerCollect> getPageByParamAll(PageRequest<QueryClueCustomerCollectAllRequest> request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());


		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		if(EmptyUtils.isEmpty(request.getParamData())){
			QueryClueCustomerCollectAllRequest clueCustomerCollect = new QueryClueCustomerCollectAllRequest();
			clueCustomerCollect.setFollowEmpId(empId);
			request.setParamData(clueCustomerCollect);
		}else{
			request.getParamData().setFollowEmpId(empId);
		}
		return clueCustomerCollectService.getPageByParamAll(request);
	}

	/**
	 * 线索跟进列表头部显示
	 *
	 * @param: id
	 * @return: ClueFollowHeadResponse
	 */
	@Override
	public ClueFollowHeadResponse getHeadContent(QueryClueCustomerCollectAllRequest clueRequest) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());

		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		clueRequest.setFollowEmpId(empId);
		return clueCustomerCollectService.getHeadContent(clueRequest);
	}

	/**
	 * 头部部跟进内容统计
	 * @param request
	 * @return 头部部跟进内容统计
	 */
	@Override
	public 	List<ClueFollowHeadTypeResponse>  getClueFollowHeadTypeResponse(ClueCustomerCollect request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());

		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		request.setFollowEmpId(empId);
		return clueCustomerCollectService.getClueFollowHeadTypeResponse(request);
	}



	/**
	 * 线索状态头部部跟进内容统计
	 * @param request
	 * @return 头部部跟进内容统计
	 */
	@Override
	public List<ClueFollowHeadTypeResponse> getClueStatusHeadTypeResponse(QueryClueCustomerCollectAllRequest request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());

		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		request.setFollowEmpId(empId);
		return clueCustomerCollectService.getClueStatusHeadTypeResponse(request);
	}

	/**
	 * 头部部战败审批统计
	 * @param request
	 * @return 头部部战败审批统计
	 */
	@Override
	public List<ClueFollowHeadTypeResponse> getClueFailFollowHeadTypeResponse(QueryClueCustomerCollectAllRequest request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());

		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		request.setFollowEmpId(empId);
		return clueCustomerCollectService.getClueFailFollowHeadTypeResponse(request);
	}


	/**
	 * 单条数据查询统计 ClueCustomerCollect
	 * @param request
	 * @return 插入的条数
	 */
	@Override
	public int getClueCustomerCollect(QueryClueCustomerCollectAllRequest request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());

		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		request.setFollowEmpId(empId);
		return clueCustomerCollectService.getClueCustomerCollect(request);
	}

	@Override
	public 	PageResponse<ClueExpirePesponse>  getOemOrDealerClueExpireList(PageRequest<ClueExpireRequest>  request) {
		//入参当前人信息
		String empIdStr = SearchLocalHeader.getHeader(SCRMRequestHeaderEnum.HEADER_EMP_ID.getCode());


		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(empIdStr, "获取当前用户信息empID为空");
		Long empId = Long.valueOf(empIdStr);
		if(EmptyUtils.isEmpty(request.getParamData())){
			ClueExpireRequest clueExpireRequest = new ClueExpireRequest();
			clueExpireRequest.setFollowEmpId(empId);
			request.setParamData(clueExpireRequest);
		}else{
			request.getParamData().setFollowEmpId(empId);
		}
		return clueCustomerCollectService.getOemOrDealerClueExpireList(request);
	}


}
